const userModel = require("../model/userModel");
//分页查询
module.exports.find = async function (searchObj, page) {
    console.log("Dao", searchObj);
    let { current, pageSize } = page;

    let total = await userModel.countDocuments(searchObj);

    let data = await userModel.find(searchObj).limit(pageSize).skip((current - 1) * pageSize);
    return {
        current, pageSize, total, rows: data
    }
}
//查询所有
module.exports.findAll = async function () {
    return await userModel.find();
}
// 登录查询是否存在
module.exports.findByUsername = async function (username) {
    console.log(username);
    console.log(await userModel.find({ openid: username }));
    return await userModel.find({ openid: username })
}
//增加
module.exports.insert = async function (user) {
    return await userModel.create(user);
};
//id查找
module.exports.findById = async function (id) {
    return await userModel.findById(id);
};
// 修改
module.exports.update = async function (user) {
    return await userModel.updateOne({ _id: user.id }, user);
}
//删除
module.exports.remove = async function (id) {
    return await userModel.remove({ _id: id });
};